package com.dfbz.demo01;

import java.util.*;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo08_Hashtable {
    public static void main(String[] args) {


        Hashtable<Integer, String> hashtable = new Hashtable<>();
        hashtable.put(1, "拌粉");
        hashtable.put(2, "汤粉");
        hashtable.put(3, "炒粉");
        hashtable.put(4, "泡粉");

        Enumeration<Integer> keys = hashtable.keys();

        while (keys.hasMoreElements()) {
            Integer key = keys.nextElement();

            if (key == 2) {
                /*
                    Hashtable在使用Enumeration遍历时,允许对集合进行增删操作
                    注意: Hashtable使用foreach迭代也不能对元素进行增删操作
                 */
                hashtable.put(5, "扎粉");
//                hashtable.remove(3);
            }
        }

        System.out.println(hashtable);
    }
}
